//
//  MainViewController.m
//  MVP
//
//  Created by 曹敬贺 on 16/8/4.
//  Copyright © 2016年 北京无限点乐科技有限公司. All rights reserved.
//

#import "MainViewController.h"


@interface MainViewController ()<MainPresenterDelegate>

@property (nonatomic, strong) UITableView * mainTable;

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.mainTable];
    [self updateViewConstraints];
}
- (void)updateViewConstraints
{
    [super updateViewConstraints];
    CGFloat width = CGRectGetWidth(self.view.bounds);
    CGFloat height = CGRectGetHeight(self.view.bounds);
    self.mainTable.frame = CGRectMake(0, 0, width, height);
    [self.presenter requestData];
}


- (void)setUser:(User *)user
{
    _user = user;
    self.presenter.user = user;
}

#pragma mark - Lzay
- (MainPresenter *)presenter
{
    if (! _presenter)
    {
        _presenter = [[MainPresenter alloc]init];
        _presenter.delegate = self;
    }
    return _presenter;
}
- (UITableView *)mainTable
{
    if (! _mainTable) {
        _mainTable = [[UITableView alloc]init];
        _mainTable.delegate = self.presenter;
        _mainTable.dataSource = self.presenter;
    }
    return _mainTable;
}

- (void)requestFinished
{
    [self.mainTable reloadData];
}


@end
